﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;

namespace CodeTalk.CTSpeechCommands
{
    public abstract class SpeechCommand
    {
        internal abstract GrammarBuilder GrammarBld(Context context, Context[] libraries);

        public bool Active { get; set; }

        internal virtual string SemanticKey
        {
            get { return Name + "SpeechCommand"; }
        }

        public abstract string Name { get;}
        public abstract string Description { get; }

        internal virtual bool IsUndoable
        {
            get { return true; }
        }

        public virtual string GetAlternativesFeedback(string recognizedText, SemanticValue semValue)
        {
            return Name;
        }

        public SpeechCommand()
        {
            Active = true;
        }

        internal abstract bool CanSpokenFormMatch(string spokenForm);

        /// <summary>
        /// Executes this specific command. 
        /// </summary>
        /// <param name="callingMode"></param>
        /// <param name="recognizedText"></param>
        /// <param name="commandData"></param>
        /// <returns>An object this command can use to undo this perticular action. See example in LearnVariable</returns>
        internal abstract object Execute(SpeechMode callingMode, string recognizedText, SemanticValue semValue);

        internal virtual void Undo(SpeechMode callingMode, string recognizedText, SemanticValue semValue, object undoObject)
        {
            if (undoObject != null)
                callingMode.CurrentOutputHandler.SendKeys((string)undoObject);
        }
    }
}
